package com.lftea.util;

import java.io.UnsupportedEncodingException;

import org.apache.log4j.Logger;

public class StringUtils {
	public static Logger logger = Logger.getLogger(StringUtils.class.getName());

		
	/**
	 * 将字符串编码由ISO8859_1转换成GBK
	 * @param str	需要转码的字符串
	 * @return	转码后的字符串
	 */
	public static String toGBK(String str) {
		if (str == null) {
			return null;
		}
		try {
			str = new String(str.getBytes("ISO8859_1"), "GBK");
		} catch (UnsupportedEncodingException e) {
			logger.error(e.getMessage());
		}
		return str;
	}
	
	public static String toISO(String str) {
		if (str == null) {
			return null;
		}
		try {
			str = new String(str.getBytes("GBK"), "ISO8859_1");
		} catch (UnsupportedEncodingException e) {
			logger.error(e.getMessage());
		}
		return str;
	}	

	/**
	 * 字符编码转换，GBK --> UTF-8 
	 * @param str
	 * @return
	 */
	public static String toUTF(String str) {
		if (str == null) {
			return null;
		}
		try {
			str = new String(str.getBytes("GBK"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			logger.error(e.getMessage());
		}
		return str;
	}
}
